package yl.hs.bmipfull.service.system.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yl.hs.bmipfull.daos.system.ISystemLogDao;
import yl.hs.bmipfull.pojo.system.SystemLogEntity;
import yl.hs.bmipfull.service.system.ISystemLogService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.PageResult;

import java.util.HashMap;
import java.util.Map;

/**
 * SystemLogServiceImpl
 *
 * @author 谢景广
 * @category
 * @date 2021-05-10
 */
@Service
public class SystemLogServiceImpl extends SystemBaseService implements ISystemLogService {


    @Autowired
    ISystemLogDao logDao;

    @Override
    public PageResult<SystemLogEntity> queryLogPage(PageQuery query, int rowNum, int page) {
        Map<String, Object> queryParam = new HashMap<String, Object>();
        if (query.getQuery().containsKey("keyword")) {
            queryParam.put("key", String.format("%%%s%%", query.getQuery().get("keyword")));
        }
        PageResult<SystemLogEntity> result = new PageResult(rowNum);
        result.setRecords(logDao.queryCountByCondition(queryParam));
        result.setPage(page);
        queryParam.put("querySkip", (page - 1) * rowNum);
        queryParam.put("pageSize", rowNum);
        query.checkSortSides(SystemLogEntity.class);
        queryParam.put("sortSide", String.join(",", query.getSortSides()));
        result.setData(logDao.queryListByCondition(queryParam));
        return result;
    }
}
